{extend name="base" /}
{block name="title"}后台管理-网络报修管理{/block}
{block name="main"}
<div class="widget-body" style="padding-bottom: 60px;">
    <!-- <div> <input style="float: left;" type="text"><button style="margin-left: 5px;margin-top: 2px;">Search</button>
    </div> -->
    <div class="span2">
        <!-- <div id="users_length" class="dataTables_length">
            <label>
                Entries: <select size="1" name="users_length"
                    aria-controls="users">
                    <option value="10" selected="selected">10</option>
                    <option value="25">25</option>
                    <option value="50">50</option>
                    <option value="100">100</option>
                </select>
            </label>
        </div> -->
    </div>
    <div class="span6">
        <div class="dataTables_filter" id="users_filter">
            <label>
                <input type="text" aria-controls="users" name="Search" placeholder="Search">
            </label>
        </div>
    </div>
    <table id="schools" class="table table-striped table-bordered dataTable">
        <thead>
            <tr>
                <th>学校</th>
                <th></th>
            </tr>
        </thead>
        <tbody class="schoollist">
            {volist name="school" id="vo"}
            <tr title="{$vo.schoolName}">
                <td>
                    <div class="line-limit-length">{$vo.schoolName}</div>
                </td>
                <td>
                    <div class="btn-group">
                        <a class="btn btn-small dropdown-toggle" data-toggle="dropdown" href="#">
                            操作
                            <span class="caret"></span>
                        </a>
                        <ul class="dropdown-menu pull-right">
                            <li><a href="{:url('edit',['sid'=>$vo.schoolId])}"><i class="icon-edit"></i> 修改</a>
                            </li>
                            <li><a href="{:url('del',['sid'=>$vo.schoolId])}"><i class="icon-trash"></i> 删除</a>
                            </li>
                        </ul>
                    </div>
                </td>
            </tr>
            {/volist}
        </tbody>
    </table>
    <div class="dataTables_paginate paging_bootstrap pagination">
        <!-- <ul>
            <li class="prev disabled">
                <a href="#">← Previous</a>
            </li>
            <li class="active">
                <a href="#">1</a>
            </li>
            <li class="next disabled">
                <a href="#">Next → </a>
            </li>
        </ul> -->
    </div>
</div> <!-- /widget-body -->
<script src="__STATIC__/assets/js/jquery.min.js"></script>
<script>
    $("[name='Search']").on("change", function () {
        console.log($(this).val());
        let key = $(this).val();
        $.ajax({
            type: 'post',
            url: "{:url('school/search')}",
            data: {
                "key": key,
            },
            success: function (data) {
                let json = JSON.parse(data);
                console.log(json);
                $('.schoollist').empty();
                if (json.length == 0) {
                    $(".schoollist").append("<h5 style='margin: 10px;color: red;'>没有找到任何学校</h5>");
                } else {
                    for (let index = 0; index < json.length; index++) {
                        const element = json[index];
                        var newb = document.createElement('tr');
                        var b = `                
                        <td>
                            <div class="line-limit-length">${element.schoolName}</div>
                        </td>
                        <td>
                            <div class="btn-group">
                                <a class="btn btn-small dropdown-toggle" data-toggle="dropdown" href="#">
                                    操作
                                    <span class="caret"></span>
                                </a>
                                <ul class="dropdown-menu pull-right">
                                    <li><a href="edit?sid=${element.schoolId}"><i class="icon-edit"></i> 修改</a>
                                    </li>
                                    <li><a href="del?sid=${element.schoolId}"><i class="icon-trash"></i> 删除</a>
                                    </li>
                                </ul>
                            </div>
                        </td>`;
                        newb.innerHTML = b;
                        $('.schoollist').append(newb);
                    }

                }
            },
            error: function (error) {
                console.log(error);
            }
        });
    });
</script>
{/block}
